package com.yonyou.pmclouds.workflow.service.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workflow.entity.ProcessDefinitionVO;
import com.yonyou.pmclouds.workflow.mapper.ProcessDefinitionMapper;
import com.yonyou.pmclouds.workflow.service.rmiitf.ProcessDefinitionQueryService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = ProcessDefinitionQueryService.class)

public class ProcessDefinitionQueryServiceImp implements ProcessDefinitionQueryService {

    @Autowired
    private ProcessDefinitionMapper mapper;

    @Override
    public ProcessDefinitionVO[] queryProcDefVOByBilltype(String billType,String pkTenant,String pkOrg) throws BusinessException {
        //根据租户主键、单据类型以及组织主键查询出流程对象。
        ProcessDefinitionVO[] definitionVOs = mapper.getStartProcessByType(pkTenant,billType,pkOrg);

        if(ArrayUtils.isEmpty(definitionVOs))
            return new ProcessDefinitionVO[0];
        return definitionVOs;
    }

    @Override
    public ProcessDefinitionVO queryProcDefVOByDefiniton(String definitionKey) {
        ProcessDefinitionVO[] definitionVOs = mapper.queryByProcessKey(definitionKey);

        if(ArrayUtils.isEmpty(definitionVOs))
            return null;
        return definitionVOs[0];
    }
}
